package com.gc;

/**
 *
 */
public class CanReliveObj {

    private static Object obj ;

    @Override
    protected void finalize() throws Throwable {

        super.finalize();
        System.out.println("调用当前重写类");
        obj = this;
    }


    public static void main(String[] args) {
        try {
            obj = new CanReliveObj();
            //赋空
            obj = null;
            System.gc();
            System.out.println("第1次gc");
            Thread.sleep(2000);
            if(obj == null){
                System.out.println("对象死了");
            }else{
                System.out.println("对象存活");
            }
            System.out.println("第2次gc");
            Thread.sleep(2000000);
            if(obj == null){
                System.out.println("对象死了");
            }else{
                System.out.println("对象存活");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
